package com.example.a24098.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Stack;

public class MainActivity extends AppCompatActivity {
    Stack<String> stack = new Stack();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new myButtonListener());
        Button button2 = (Button)findViewById(R.id.button2);
        button2.setOnClickListener(new myButtonListener2());
    }

    public class myButtonListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            EditText editText1 = (EditText) findViewById(R.id.editText1);
            stack.push(editText1.getText().toString());
            System.out.println(editText1.getText().toString());
            EditText editText2 = (EditText) findViewById(R.id.editText2);
            editText2.setText(editText1.getText(), TextView.BufferType.EDITABLE);
            editText2.setText(stack.toString(), TextView.BufferType.EDITABLE);
        }
    }
    public class myButtonListener2 implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            EditText editText1=(EditText)findViewById(R.id.editText1);
            int x = Integer.parseInt(stack.pop());
            System.out.println(editText1.getText().toString());
            EditText editText2=(EditText)findViewById(R.id.editText2);
            editText2.setText(editText1.getText(), TextView.BufferType.EDITABLE);
            editText2.setText(stack.toString(),TextView.BufferType.EDITABLE);
        }
    }
}

